from const import gofile_path


def genGolangfile(protos,cmdArray):
    fileContent = ""
    fileContent += (
    'package msg'
    '\n'
    'import (\n'
    '   "github.com/chenwbyx/leafserver/server/msg/client"\n'
    '   "github.com/chenwbyx/leafserver/server/proto"\n'
    ')'
    '\n\n'
    'var (\n'
    '   Processor = proto.NewProcessor()\n'
    ')\n'
    '\n'
    'func init() {'
     '  // 这里我们注册 protobuf 消息)\n'
     '    Processor.SetByteOrder(false)\n'
    )

    # Processor.Register(uint16(CmdAccountInfo), &client.AccountInfo

    for cmdName in  cmdArray:
        for protoName in protos:
            if protoName in cmdName:
                fileContent += '' \
                               '    Processor.Register(uint16(client.ClientCmd_'
                fileContent += cmdName
                fileContent += '),&client.'
                fileContent += protoName
                fileContent += '{})\n'

    fileContent += ("\n}")

    fo = open(gofile_path, "wb")
    fo.write(fileContent.encode('utf-8'))
    fo.close()


